#coding:utf-8
from django.contrib.auth.models import User
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.utils.translation import ugettext_lazy as _

#附件
class Attachment(models.Model):
    content_type = models.ForeignKey(ContentType, null=True)
    object_id = models.PositiveIntegerField(null=True)
    content_object = generic.GenericForeignKey('content_type', 'object_id')
    realname = models.CharField(max_length=32)
    type = models.CharField(max_length=32)
    file = models.FileField(upload_to='files')
    ctime = models.DateTimeField(auto_now_add=True)
    uploader = models.ForeignKey(User, blank=True, null=True)
    #FIXME: fix this .. URLField.. instead of get_absolute_url
    url = models.URLField(null=True)

    def __unicode__(self):
        return self.realname

    def get_absolute_url(self):
        return ''

class AttachmentModel(models.Model):
    attachments = generic.GenericRelation(Attachment)

    class Meta:
        abstract = True
